package algorithms;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lizen
 */
public class FindAppearanceOnceInArr {
    public static Integer find(Integer[] intArr) {
        HashMap<Integer, Integer> intHash = new HashMap<>();
        for (Integer key : intArr) {
            if (intHash.containsKey(key)) {
                Integer curCount = intHash.get(key);
                intHash.put(key, curCount+1);
            } else {
                intHash.put(key, 1);
            }
        }

        for (Map.Entry<Integer, Integer> entry : intHash.entrySet()) {
            if (entry.getValue() == 1) {
                return entry.getKey();
            }
        }

        return Integer.MIN_VALUE;
    }

    public static void test() {
        Integer[] sourceList = new Integer[]{1, 1, 2, 2, 4};
        System.out.println(find(sourceList));
    }
}
